<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ajax返回字符</title>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function showHint(str){
//var xmlhttp;
//if (str.length==0)
//  {
//  document.getElementById("txtHint").innerHTML="";
//  return;
//  }
//if (window.XMLHttpRequest)
//  {// code for IE7+, Firefox, Chrome, Opera, Safari
//  xmlhttp=new XMLHttpRequest();
//  }
//else
//  {// code for IE6, IE5
//  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
//  }
//xmlhttp.onreadystatechange=function()
//  {
//  if (xmlhttp.readyState==4 && xmlhttp.status==200)
//    {
//    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
//    }
//  }
//xmlhttp.open("GET","gethint.php?q="+str,true);
//xmlhttp.send();
var selectobj = '#test';
$.get("gethint.php","q="+str, function(data){
		$(selectobj).empty();
		//$("<option value='0'>==请选择==</option>").appendTo(selectobj);
        if(data!=""){
            var arr=data.split(';');
			var txt="";
            for(var i=0;i<arr.length;i++){
				if(i==0) txt+="<option value='"+arr[i].split(',')[0]+"' selected>"+arr[i].split(',')[0]+' - '+arr[i].split(',')[1]+"</option>";
				else  txt+="<option value='"+arr[i].split(',')[0]+"'>"+arr[i].split(',')[0]+' - '+arr[i].split(',')[1]+"</option>";
                $(txt).appendTo(selectobj);
            }
        }
    });

}
</script>
</head>
<body>

<h3>请在下面的输入框中键入字母（A - Z）：</h3>
<form action="test.php" method="post">
姓氏：<input type="text" id="txt1" onKeyUp="showHint(this.value)" />
<p>建议：<span id="txtHint"></span></p>
<select name="test" id="test"></select><br />
<input type="submit" value="测试提交" />
</form>
</body>
</html>